// pages/work/xaingqing/index.js
const my=require("../../../utils/MyUtils")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    leave_type:[
      "","事假",  "病假",  "年假",  "调休",  "婚假",  "产假", "陪产假",  "其他"
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var list2={}
    var t = this
    var _TOKEN = wx.getStorageSync('_TOKEN')
    my.request("/oa-applet/application-detail", "get", {
      apply_type: options.apply_type,
      apply_id: options.apply_id
    }, {
      token: _TOKEN
    }, function (res) {
      console.log(res)
      wx.hideLoading()
      if (res.data.code == 0) {
        var data = res.data.data
        list2.user_name = data.user_name
        list2.department_name = data.department_name
        list2.station_name = wx.getStorageSync('userInfo').station_name.substr(0,5)
        if(options.apply_type==1){
          list2.start_time = data.leave_detail.start_time
          list2.num = data.leave_detail.num
          list2.reason = data.leave_detail.reason
          list2.end_time = data.leave_detail.end_time
          list2.type =  t.data.leave_type[data.leave_detail.type]
          list2.status = data.leave_detail.status
          list2.shrq = data.leave_detail.created_at
          list2.list = data.leave_apply_detail
          list2.ycType = 1
        }
        if(options.apply_type==2){
          list2.start_time=data.out_detail.start_time
          list2.end_time=data.out_detail.end_time
          list2.num=data.out_detail.num
          list2.address=data.out_detail.address
          list2.reason=data.out_detail.reason
          list2.status=data.out_detail.status
          list2.shrq=data.out_detail.created_at
          list2.list=data.out_apply_detail
          list2.ycType = 2
        }
        if(options.apply_type==3){
          list2.start_time = data.business_detail.start_time
          list2.num = data.business_detail.num
          list2.reason = data.business_detail.reason
          list2.end_time = data.business_detail.end_time
          list2.address = data.business_detail.address
          list2.status = data.business_detail.status
          list2.shrq = data.business_detail.created_at
          list2.list = data.business_apply_detail
          list2.ycType = 3
        }

        if(options.apply_type==4){
          list2.start_time = data.overtime_detail.start_time
          list2.num = data.overtime_detail.num
          list2.reason = data.overtime_detail.reason
          list2.end_time = data.overtime_detail.end_time
          data.overtime_detail.type == 1 ? list2.type = '工作日' : (data.overtime_detail.type == 2 ? list2.type = '休息日' : list2.type = '法定假日')
          list2.status = data.overtime_detail.status
          list2.shrq = data.overtime_detail.created_at
          list2.list = data.overtime_apply_detail
          list2.ycType = 4
        }
        if(options.apply_type==5){
          list2.witness = data.patch_card_detail.witness
          list2.reason = data.patch_card_detail.reason
          list2.date = data.patch_card_detail.date
          list2.type = data.patch_card_detail.type
          list2.status = data.patch_card_detail.status
          
          list2.shrq = data.patch_card_detail.created_at
          list2.list = data.patchcard_apply_detail
          list2.ycType = 5
        }
        data.user_name.length >= 3 ? list2.nick_name = data.user_name.substr(1, data.user_name.length - 1) : list2.nick_name = data.user_name
        for (var i = 0; i < list2.list.length; i++) {
          list2.list[i].user_name.length >= 3 ? list2.list[i].nick_name = list2.list[i].user_name.substr(1, list2.list[i].user_name.length - 1) : list2.list[i].nick_name = list2.list[i].user_name
        }
        
        t.setData({
          list2,
        })
        
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // consoloptions.log(options)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (op) {
    // consoloptions.log(op)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})